//背景拉升
let img = $('#top_bigimg'); //背景图片
let con = $('#header-bg');//背景图片容器
let wid = con.offsetWidth;//容器宽度
let Height = document.documentElement.clientHeight//设备高度
let flag = true;
let count = "";
let stop1 = false;//图片复原下变为true
let stop2 = false;//图片复原下变为true
let conHeight;
window.addEventListener("touchstart", function (e) {
    let top = document.documentElement.scrollTop; //滚动条位置
    let count = e.touches.length;//几根手指触摸
    //判断是否是在图片复原状态下再次下拉
    if (stop1) {
        con.stop();
        img.stop();
        conHeight = con.height();
        stop1 = false;
        stop2 = true;
        if (count == 1) {
            let startY = e.changedTouches[0].clientY; //触摸开始Y位置
            st1 = [startY];
            return st1;
        } else {
            flag = false;
        }
    } else {
        if (count == 1) {
            if (!top) {//是否在顶部
                let startY = e.changedTouches[0].clientY; //触摸开始Y位置
                st = [startY];
                return st;
            }
        } else {
            flag = false;
        }
    }
});
//监听滑动距离
window.addEventListener("touchmove", function (eve) {
    if (stop2&&flag) {
        let Y = eve.changedTouches[0].clientY;//滑动Y位置
        let distanceY = Y - st1[0];//Y移动距离
        if (distanceY>20) {
            let num = (distanceY-20) / 2
            let max = Height / 2;
            let height = num + conHeight;
            if (num >= 0 && height < max) {
                con.css({
                    'height': conHeight + num + "px",
                });
            }
        }
    } else {
        if (flag) {
            let Y = eve.changedTouches[0].clientY;//滑动Y位置
            let distanceY = Y - st[0];//Y移动距离
            let top = document.documentElement.scrollTop;//滚动条位置
            if (distanceY > 20 && top == 0) {
                let num = (distanceY - 20) / 2
                let height = num + 150;
                let max = Height / 2;
                if (num >= 0 && height < max) {
                    con.css({
                        'height': 150 + num + "px",
                        'width': wid + num + "px",
                    });
                    if (num < 120) {
                        img.css("zoom", num / 100 + 1);
                    }
                }
            }
        }
    }
});
window.addEventListener("touchend", function (end) {
    count = end.touches.length;
    if(count == 0){
        resize()
    }
})
//恢复尺寸
function resize() {
    stop1 = true;
    stop2=false;
    if (count == 0) {
        con.animate({
            height: 150 + "px",
            width: wid + "px",
        }, 500)
        img.animate({
            zoom: 1,
        }, 500);
        flag = true;
    }
}

